
//
//  TiaoZiListVC.m
//  tristana
//
//  Created by bug neo on 05/01/2021.
//  Copyright © 2021 李康. All rights reserved.
//  借条 || 欠条

#import "TiaoZiListVC.h"

#import "TZCell.h"

#import <MJRefresh/MJRefresh.h>

@interface TiaoZiListVC () <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@end

@implementation TiaoZiListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initAllPropertys];
    [self setupUI];
    [self queryData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (self.fromMine) {
        self.navigationController.navigationBarHidden = NO;
    }
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    if (self.fromMine) {
        self.navigationController.navigationBarHidden = YES;
    }
}

#pragma mark - Public Method

#pragma mark - Life Cycle

#pragma mark - Data Query
- (void)queryData {
    if (self.type == 0) {
        NSMutableArray *arr1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"recordData1"];
        self.dataSource = [arr1 mutableCopy];
        
    }else {
        NSMutableArray *arr2 = [[NSUserDefaults standardUserDefaults] objectForKey:@"recordData2"];
        self.dataSource = [arr2 mutableCopy];
    }
    [self.tableView reloadData];
    
}
#pragma mark - Notification

#pragma mark - UI
- (void)initAllPropertys {
    
}

- (void)setupUI {
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"TZCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"TZCell"];
    
    __weak typeof(self) weakSelf = self;
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [weakSelf queryData];
        [weakSelf.tableView.mj_header endRefreshing];
    }];
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
    }];
}
#pragma mark - Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TZCell *cell = (TZCell *)[tableView dequeueReusableCellWithIdentifier:@"TZCell" forIndexPath:indexPath];
    cell.type = self.type;
    cell.dic = self.dataSource[indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 105;
}
#pragma mark - Private Method

#pragma mark - Overwrite Method

#pragma mark - Event Response

#pragma mark - Setter

#pragma mark - Getter
- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        _dataSource = [NSMutableArray array];
    }
    return _dataSource;
}
@end
